home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / sbin / pmi < prev    next >
Text File  |  2008-01-15  |  3KB  |  96 lines

  1. #!/bin/bash
  2.  
  3. # This is the ACPI version of the shell version of PMI
  4.  
  5. # calling convention: pmi <event>
  6.  
  7. command="$1"
  8. event="$2"
  9.  
  10. usage () {
  11.         echo "Usage: $0 query|action <event>" >&2
  12.         echo "       $0 capabilities" >&2
  13.         exit 254
  14. }
  15.  
  16. query () {
  17.         [ ! -z "$1" ] && event="$1" 
  18.         case "$event" in
  19.                 suspend|sleep)                
  20.                         if grep -q ' /host fuse' /proc/mounts; then
  21.                                 # Disallow suspend when we're mounting /
  22.                                 # from a loopback image on a fuse
  23.                                 # filesystem.
  24.                                 result=1
  25.                         else
  26.                 pm-is-supported --suspend && result=0 || result=1
  27.             fi
  28.                 ;;
  29.                 hibernate)
  30.                         if grep -q ' /host fuse' /proc/mounts || \
  31.                            ! swapon -s | tail -n +2 | awk '$2 == "file" { exit 1 }'; then
  32.                                 # Disallow hibernate when we're mounting /
  33.                                 # from a loopback image on a fuse
  34.                                 # filesystem, or when a swap file is active.
  35.                                 result=1
  36.                         elif [ -f /var/run/do-not-hibernate ]; then
  37.                                 result=1
  38.                         else
  39.                                 pm-is-supported --hibernate && result=0 || result=1
  40.                         fi
  41.                 ;;
  42.                 *)
  43.                         result=1
  44.                         echo "No such event found" >&2
  45.                         ;;
  46.         esac
  47. }
  48.                         
  49. run () {
  50.         case "$event" in
  51.                 suspend|sleep)
  52.                         [ -f /var/lock/acpisleep ] && exit 0
  53.             dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0
  54.                 ;;
  55.                 hibernate)
  56.                 [ -f /var/lock/acpisleep ] && exit 0
  57.             [ -f /var/run/do-not-hibernate ] && echo "Default kernel has been upgraded" >&2 && exit 1
  58.             dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate
  59.                 ;;
  60.         restart)
  61.                [ -f /var/lock/acpisleep ] && exit 0
  62.                shutdown -r now
  63.         ;;
  64.         shutdown)
  65.                [ -f /var/lock/acpisleep ] && exit 0
  66.                shutdown -h now
  67.         ;;
  68.         esac
  69. }
  70.                 
  71. capabilities () {
  72.         for i in "hibernate" "suspend"; do
  73.                 query $i
  74.                 [ $result -eq 0 ] && caps="$caps $i"
  75.         done
  76.         echo $caps
  77. }
  78.  
  79. case "$command" in
  80.         query)
  81.                 query $event
  82.                 exit $result
  83.                 ;;
  84.         action)
  85.                 run $event
  86.                 ;;
  87.         capabilities)
  88.                 capabilities
  89.                 ;;
  90.         *)
  91.                 usage
  92.                 ;;
  93. esac
  94.  
  95. exit 0
  96.